import { LOGIN_QUIT, LOGIN_SUCCESS, UserAction } from "./userActions";
import { l } from "../../utils";
const initState = {
  username: "",
  nickname: "",
  avator: "",
  token: l.getItem("token") || "",
  role: "",
};
export type UserState = typeof initState;
const userReducer = (state = initState, action: UserAction) => {
  switch (action.type) {
    case LOGIN_SUCCESS: {
      return { ...state, ...action.payload };
    }
    case LOGIN_QUIT: {
      return { username: "", nickname: "", avator: "", token: "", role: "" };
    }
    default:
      return state;
  }
};
export default userReducer;
